home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / fbm12s.lha / fbrot.c < prev    next >
C/C++ Source or Header  |  1994-07-18  |  3KB  |  99 lines

  1. /*****************************************************************
  2.  * fbrot.c: FBM Release 1.2 07-Apr-93 Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989-1993 by Michael Mauldin.  Permission is granted
  5.  * to use this file in whole or in part for any purpose, educational,
  6.  * recreational or commercial, provided that this copyright notice
  7.  * is retained unchanged.  This software is available to all free of
  8.  * charge by anonymous FTP and in the UUNET archives.
  9.  *
  10.  * fbrot.c: Rotate image 90 degrees clockwise
  11.  *
  12.  * USAGE
  13.  *     % fbrot < image1 > image2
  14.  *
  15.  * EDITLOG
  16.  *     LastEditDate = Mon Jun 25 00:04:32 1990 - Michael Mauldin
  17.  *     LastFileName = /usr2/mlm/src/misc/fbm/fbrot.c
  18.  *
  19.  * HISTORY
  20.  * 07-Apr-93  Michael Mauldin (mlm) at Carnegie-Mellon University
  21.  *    Added -J switch
  22.  *
  23.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  24.  *    Package for Release 1.0
  25.  *
  26.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  27.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  28.  *
  29.  * 22-Aug-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  30.  *     Created.
  31.  *****************************************************************/
  32.  
  33. # include <stdio.h>
  34. # include <math.h>
  35. # include "fbm.h"
  36.  
  37. # define USAGE \
  38.   "Usage: fbrot [ -<type> ] [ -90 | -180 | -270 ] < image > image"
  39.  
  40. #ifndef lint
  41. static char *fbmid =
  42. "$FBM fbrot.c <1.2> 07-Apr-93 (C) 1989-1993 by Michael Mauldin, source \
  43. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  44. #endif
  45.  
  46. main (argc, argv)
  47. char *argv[];
  48. { FBM input, output;
  49.   int outtype = -1, rot = 90;
  50.  
  51.   /* Get the options */
  52.   while (--argc > 0 && (*++argv)[0] == '-')
  53.   { while (*++(*argv))
  54.     { switch (**argv)
  55.       {
  56.     case '9':    rot=90; SKIPARG; break;
  57.     case '1':    rot=180; SKIPARG; break;
  58.     case '2':    rot=270; SKIPARG; break;
  59.     case 'A':    outtype = FMT_ATK; break;
  60.     case 'B':    outtype = FMT_FACE; break;
  61.     case 'F':    outtype = FMT_FBM; break;
  62.     case 'G':    outtype = FMT_GIF; break;
  63.     case 'I':    outtype = FMT_IFF; break;
  64.     case 'J':    outtype = FMT_JPEG; break;
  65.     case 'L':    outtype = FMT_LEAF; break;
  66.     case 'M':    outtype = FMT_MCP; break;
  67.     case 'P':    outtype = FMT_PBM; break;
  68.     case 'R':    outtype = FMT_RLE; break;
  69.     case 'S':    outtype = FMT_SUN; break;
  70.     case 'T':    outtype = FMT_TIFF; break;
  71.     case 'X':    outtype = FMT_X11; break;
  72.     case 'Z':    outtype = FMT_PCX; break;
  73.     default:        fprintf (stderr, "%s\n", USAGE);
  74.                         exit (1);
  75.       }
  76.     }
  77.   }
  78.  
  79.   /* Clear the memory pointers so alloc_fbm won't be confused */
  80.   input.cm  = input.bm  = (unsigned char *) NULL;
  81.   output.cm = output.bm = (unsigned char *) NULL;
  82.  
  83.   /* Read the image and rotate it */
  84.   if (read_bitmap (&input, (char *) NULL))
  85.   { if (outtype < 0)
  86.     { if (input.hdr.planes == 1 && input.hdr.bits == 1)
  87.       { outtype = DEF_1BIT; }
  88.       else
  89.       { outtype = DEF_8BIT; }
  90.     }
  91.  
  92.     if (rotate_fbm (&input, &output, rot) &&
  93.         write_bitmap (&output, stdout, outtype))
  94.     { exit (0); }
  95.   }
  96.  
  97.   exit (1);
  98. }
  99.